package cn.edu.ctbu.lablist.service.impl;

import cn.edu.ctbu.lablist.domain.Score;
import cn.edu.ctbu.lablist.domain.Student;
import cn.edu.ctbu.lablist.repository.ScoreRepository;
import cn.edu.ctbu.lablist.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScoreimplService implements ScoreService {

    @Autowired
    private ScoreRepository scoreRepository;


    public List<Score> findAll(){
        return scoreRepository.findAll();
    }


    /**
     * 只分页的查询
     * @param pageable
     * @return
     */
    public Page<Score> findAll(Pageable pageable) {
        return scoreRepository.findAll(pageable);
    }

    /**
     *分页，带过滤的查询
     * @param score
     * @param pageable
     * @return
     */
    public Page<Score> findAll(Example<Score> score, Pageable pageable){
        return scoreRepository.findAll(score,pageable);
    }
    /**
     * 按id进行查询
     * @param id 主键，整数
     * @return
     */
    public Score findById(Integer id){


        return scoreRepository.findById(id).orElse(null);
    }

    /**
     * 按名字进行查询,Like
     * @param sno 字符串
     * @return
     */
    public List<Score> findBySno(String sno){


        return scoreRepository.findBySnoLike(sno);
    }
    public List<Score> findByTno(String tno){


        return scoreRepository.findByTnoLike(tno);
    }

    /**
     * 按名字和密码查询
     * @param sno
     * @param tno
     * @return
     */
    public List<Score> findBySnoAndTno(String sno,String tno){


        return scoreRepository.findBySnoAndTno(sno,tno);
    }

    /**
     * 创建
     * @param score
     */
    public void insert(Score score){
        scoreRepository.save(score);
    }

    /**
     * 更新
     * @param score
     */
    public void update(Score score){
        scoreRepository.save(score);
    }

    /**
     * 删除
     * @param id
     */
    public void delete(Integer id){
        scoreRepository.deleteById(id);
    }

}